package com.dayanxs.Controller;

import com.dayanxs.Service.NovelChapterService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/novel-chapter")
public class NovelChapterController {

    private final NovelChapterService novelChapterService;

    public NovelChapterController(NovelChapterService novelChapterService) {
        this.novelChapterService = novelChapterService;
    }

    @GetMapping("/list")
    public ResponseEntity<?> getChaptersByNovelId(@RequestParam int novelId) {
        return novelChapterService.getChaptersByNovelId(novelId);
    }

    @GetMapping("/get")
    public ResponseEntity<?> getChapterById(@RequestParam int chapterId) {
        return novelChapterService.getChapterById(chapterId);
    }

    @PostMapping("/add")
    public ResponseEntity<?> addChapter(
            @RequestHeader(value = "Authorization", required = false) String authorization,
            @RequestBody Map<String, String> chapterDetails) {
        return novelChapterService.addChapter(authorization, chapterDetails);
    }

    @PostMapping("/update")
    public ResponseEntity<?> updateChapter(
            @RequestHeader(value = "Authorization", required = false) String authorization,
            @RequestBody Map<String, String> chapterDetails) {
        return novelChapterService.updateChapter(authorization, chapterDetails);
    }

    @GetMapping("/delete")
    public ResponseEntity<?> deleteChapter(
            @RequestParam int chapterId,
            @RequestHeader(value = "Authorization", required = false) String authorization) {
        return novelChapterService.deleteChapter(chapterId, authorization);
    }
}
